﻿#region codejockey.net Copyright Banner
/***************************************************************\
 * Copyright 2010 codejockey.net.                                *
 *                                                               *
 * This code is property of codejockey.net and cannot be used    *
 * without explicit permission given by a codejockey.net         *
 * Representative.  For details contact: source@codejockey.net   *
 \***************************************************************/
#endregion

using System;
using System.Configuration;
using System.Linq;

namespace codejockey.BingPaper.Configuration
{
  public class BingPaperTokenConfigElementCollection : ConfigurationElementCollection
  {
  	/// <summary>
    /// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"/>.
    /// </summary>
    /// <returns>
    /// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
    /// </returns>
    protected override ConfigurationElement CreateNewElement()
    {
      return new BingPaperTokenConfigElementCollection();
    }

    /// <summary>
    /// Gets the element key for a specified configuration element when overridden in a derived class.
    /// </summary>
    /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
    /// <returns>
    /// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
    /// </returns>
    protected override object GetElementKey(ConfigurationElement element)
    {
      return ((BingPaperTokenConfigElement)element).Trigger;
    }

    /// <summary>
    /// Gets the <see cref="codejockey.BingPaper.Configuration.BingPaperTokenConfigElement"/> at the specified index.
    /// </summary>
    /// <value></value>
    new public BingPaperTokenConfigElement this[string index]
    {
      get
      {
      	return this.Cast<BingPaperTokenConfigElement>().FirstOrDefault(element => element.Trigger.Equals(index, StringComparison.OrdinalIgnoreCase));
      }
    }
  }
}
